package ua.cn.store.impl;

import java.util.List;

import ua.cn.store.domain.User;
import ua.cn.store.service.GeneralServiceException;
import ua.cn.store.service.IUserService;

public class UserServiceImpl extends GenericServiceImpl<User> implements
		IUserService {

	public UserServiceImpl() {
		super(User.class);
	}

	@Override
	public List<User> findByName(String name) throws IllegalArgumentException,
			GeneralServiceException {
		if (name == null){
			throw new IllegalArgumentException("User name is null");
		}
		return executeQuery("User.findUserByName", true, false, name);
	}

	@Override
	protected void beforeEntityAddUpdate(User obj)
			throws GeneralServiceException {
		// TODO Auto-generated method stub
	}

	@Override
	protected void beforeEntityDelete(User obj) throws GeneralServiceException {
		// Delete account of user:
		executeUpdateQuery("DeleteByUser", true, obj.getId());
		executeUpdateQuery("Order.DeleteByUser", true, obj.getId());
		
	}

}
